document.addEventListener('DOMContentLoaded', function() {
    const loginForm = document.getElementById('loginForm');
    const errorMsg = document.getElementById('errorMsg');
    
    loginForm.addEventListener('submit', function(e) {
        e.preventDefault();
        
        const username = document.getElementById('username').value;
        const password = document.getElementById('password').value;
        const role = document.getElementById('role').value;
        
        if (username && password) {
            localStorage.setItem('username', username);
            localStorage.setItem('role', role);
            
            if (role === 'patient') {
                window.location.href = 'patient.html';
            } else {
                window.location.href = 'doctor.html';
            }
        } else {
            errorMsg.textContent = '请填写完整信息';
        }
    });
});
